import { BaseService } from '@/base/base.service';
import { pageData } from '@/util/util';
import { Injectable } from '@nestjs/common';
import { peerCar } from '@prisma/client';
import { CreatePeerCarDto } from './dto/create-peer-car.dto';

@Injectable()
export class PeerCarService {

  constructor(private readonly baseService: BaseService){}

  async create(dto: CreatePeerCarDto) {
    const peerCar = await this.baseService.peerCar.create({
      data: {
        ...dto
      }
    })
    return peerCar
  }

  async findAll() {
    return await this.baseService.peerCar.findMany()
  }

  async findPage(query: any) {
    return await pageData<peerCar>('peerCar', query)
  }

  async findOne(id: string) {
    return await this.baseService.peerCar.findUnique({
      where: {
        id
      }
    })
  }

  async createPeerImg(dto: {url: string, peerId: string}) {
    await this.baseService.peerImg.create({
      data: {
        ...dto
      }
    })
    return '添加成功'
  }

  async findPeerImg(peerId: string) {
    const peerImgList = await this.baseService.peerImg.findMany({
      where: {
        peerId
      }
    })
    return peerImgList
  }
}
